import 'package:flutter/material.dart';
import 'package:sharing/resources/code_point.dart';
import 'package:sharing/resources/font_families.dart';
import 'package:sharing/resources/colors.dart';

/**
 *    *
 *   ***   我的事件...
 *    *
 */
class FullWithButton extends StatelessWidget {
  FullWithButton(
      {@required this.iconPath,
      @required this.title,
      @required this.onPressed,
      this.num,
      this.showDivider = false})
      : assert(iconPath != null),
        assert(title != null),
        assert(onPressed != null);

  @override
  Widget build(BuildContext context) {
    final pureButton = Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Image.asset(
          iconPath,
          width: FullWithIconButtonIconSize,
          height: FullWithIconButtonIconSize,
        ),
        SizedBox(
          width: HORIZONTAL_PADDING,
        ),
        Expanded(
          child: Container(
            child: Text(
              title,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
        ),
        Container(
          child: Text(
            num == null ? "" : num,
            overflow: TextOverflow.clip,
          ),
        ),

        // 显示 类似下一曲的箭头, 表示还有更多的选项
        Container(
          margin: const EdgeInsets.only(right: 0.0, left: 8.0),
          child: Icon(
            IconData(
              IconCode.next,
              fontFamily: FontFamiles.iconFontFamily,
            ),
            size: 16,
            color: AppColor.light,
          ),
        ),
      ],
    );

// 带有下划线的按钮
    final borderedButton = Container(
      // 设置边距
      padding: EdgeInsets.only(bottom: VERTICAL_PADDING),
      decoration: BoxDecoration(
        border: Border(
            bottom: BorderSide(
          color: Color(0xffd9d9d9),
          width: 1.0,
        )),
      ),
      child: pureButton,
    );
    // 扁平化按钮
    return FlatButton(
      onPressed: onPressed,
      // 内边距
      padding: EdgeInsets.only(
          left: HORIZONTAL_PADDING,
          right: HORIZONTAL_PADDING,
          top: VERTICAL_PADDING,
          // 如果有显示下划线.. 底部的边距设置为0.0
          bottom: showDivider ? 0.0 : VERTICAL_PADDING),
      color: Colors.white,
      // 判断是否需要显示下划线
      child: showDivider ? borderedButton : pureButton,
    );
  }

  final String iconPath;
  final String title;
  final bool showDivider;
  final VoidCallback onPressed;
  String num;

  // 扁平化图标的大小
  static const FullWithIconButtonIconSize = 24.0;
  static const ICON_SIZE = 24.0;
  static const HORIZONTAL_PADDING = 20.0;
  static const VERTICAL_PADDING = 13.0;
}
